home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / NetTime.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  3.0 KB  |  90 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import java.util.Date;
  7. import symjava.sql.SQLException;
  8. import symjava.sql.Time;
  9. import symjava.sql.Timestamp;
  10.  
  11. class NetTime extends DateTimeField {
  12.    Time _timeVal;
  13.  
  14.    int getType() {
  15.       return 76;
  16.    }
  17.  
  18.    void readData(DataInputStream is) throws SQLException, IOException, ErrorException {
  19.       int iHour = 0;
  20.       ServerObject obj = (ServerObject)NetClass.getNextObject(is);
  21.       if (obj.getType() == 51) {
  22.          iHour = ((NetData)obj).getInt();
  23.       } else {
  24.          ((ServerObject)this).onObjectError(obj);
  25.       }
  26.  
  27.       int iMinutes = 0;
  28.       obj = (ServerObject)NetClass.getNextObject(is);
  29.       if (obj.getType() == 51) {
  30.          iMinutes = ((NetData)obj).getInt();
  31.       } else {
  32.          ((ServerObject)this).onObjectError(obj);
  33.       }
  34.  
  35.       int iSeconds = 0;
  36.       obj = (ServerObject)NetClass.getNextObject(is);
  37.       if (obj.getType() == 51) {
  38.          iSeconds = ((NetData)obj).getInt();
  39.       } else {
  40.          ((ServerObject)this).onObjectError(obj);
  41.       }
  42.  
  43.       this._timeVal = new Time(iHour, iMinutes, iSeconds);
  44.    }
  45.  
  46.    void writeData(DataOutputStream os) throws IOException {
  47.       NetData data = new NetData((short)this._timeVal.getHours());
  48.       data.write(os);
  49.       data = new NetData((short)this._timeVal.getMinutes());
  50.       data.write(os);
  51.       data = new NetData((short)this._timeVal.getSeconds());
  52.       data.write(os);
  53.    }
  54.  
  55.    public String getString() throws SQLException {
  56.       return ((Field)this).isNull() ? null : this._timeVal.toString();
  57.    }
  58.  
  59.    public Time getTime() throws SQLException {
  60.       return ((Field)this).isNull() ? null : this._timeVal;
  61.    }
  62.  
  63.    public void setString(String x) throws SQLException {
  64.       this._timeVal = Time.valueOf(x);
  65.       super._null = false;
  66.    }
  67.  
  68.    public void setTime(Time x) throws SQLException {
  69.       this._timeVal = x;
  70.       super._null = false;
  71.    }
  72.  
  73.    public void setTimestamp(Timestamp x) throws SQLException {
  74.       this._timeVal = new Time(((Date)x).getHours(), ((Date)x).getMinutes(), ((Date)x).getSeconds());
  75.       super._null = false;
  76.    }
  77.  
  78.    public int getSQLType() {
  79.       return 92;
  80.    }
  81.  
  82.    public Object getObject() throws SQLException {
  83.       return new Time(this._timeVal.getHours(), this._timeVal.getMinutes(), this._timeVal.getSeconds());
  84.    }
  85.  
  86.    public void setObject(Object obj) throws SQLException {
  87.       this.setTime((Time)obj);
  88.    }
  89. }
  90.